/**
 * Note DAO
 */
var DB_COLLECTION_NOTE_TB_NAME = "node";
var DB_COLLECTION_NOTE_COL_ID = "id";
var DB_COLLECTION_NOTE_COL_TITLE = "title";
var DB_COLLECTION_NOTE_COL_CONTENT = "content";
var DB_COLLECTION_NOTE_COL_CATEGORY_ID = "categoryid";
//create date
//modify date

var db = require("./dbMongo");

exports.DB_COLLECTION_NOTE_COL_TITLE = DB_COLLECTION_NOTE_COL_TITLE;
exports.DB_COLLECTION_NOTE_COL_CONTENT = DB_COLLECTION_NOTE_COL_CONTENT;
exports.DB_COLLECTION_NOTE_COL_CATEGORY_ID = DB_COLLECTION_NOTE_COL_CATEGORY_ID;

exports.all = function(handler) {
	db.connect();
	db.find(DB_COLLECTION_NOTE_TB_NAME, handler);
};

exports.findByCategoryId = function(categoryId, handler) {
	db.connect();
	var key = {DB_COLLECTION_NOTE_COL_CATEGORY_ID : categoryId};
	db.listQuery(DB_COLLECTION_NOTE_TB_NAME, key, handler);
};

exports.findByNodeId = function(noteId, handler){
	db.connect();
	var BSON = require('mongodb').BSONPure;
	var key = {_id:BSON.ObjectID.createFromHexString(noteId)};
	db.listQuery(DB_COLLECTION_NOTE_TB_NAME, key, handler);
};

exports.add = function(item, handler) {
	db.connect();
	db.add(DB_COLLECTION_NOTE_TB_NAME, item, handler);
};